package com.elesyser.alarm;

import java.util.Calendar;

import com.elesyser.main.CurriculumActivity;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.widget.Toast;

public class AlarmRegister {

	public final static String ADD = "1";
	public final static String CANCEL = "2";

	public void RegisterAlarmEntry(Context context, Calendar calendar,
			String message) {
		Intent intent = new Intent(context, AlarmReceiver.class);
		Bundle b = new Bundle();
		b.putString("type", ADD);
		b.putString("message", message);
		intent.putExtras(b);
		intent.setAction(String.valueOf(System.currentTimeMillis()));
		PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
		AlarmManager am = (AlarmManager) context
				.getSystemService(Activity.ALARM_SERVICE);

		SystemClock.sleep(3);
		calendar.setTimeInMillis(System.currentTimeMillis());

		calendar.set(Calendar.SECOND, calendar.get(Calendar.SECOND) + 5);
		am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pi);

		Intent cancelIntent = new Intent(context, AlarmReceiver.class);
		Bundle bundle = new Bundle();
		bundle.putString("type", CANCEL);
		bundle.putString("message", message);
		cancelIntent.putExtras(bundle);
		cancelIntent.setAction(String.valueOf(System.currentTimeMillis()));
		PendingIntent cancelPi = PendingIntent.getBroadcast(context, 0, cancelIntent,
				0);
		// AlarmManager cancelAm = (AlarmManager)
		// context.getSystemService(Activity.ALARM_SERVICE);
		calendar.setTimeInMillis(System.currentTimeMillis());
		calendar.set(Calendar.SECOND, calendar.get(Calendar.SECOND) + 10);
		am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), cancelPi);
	}
}
